<template>
	<view class="container" :class="'theme-'+theme">
	<view class="addTitle">
      <view class="titleDetail">
        <view class="titleLeft" > 
			<image src="../../static/newh5/fanhui.png" 
			class="yticon" 
			style="width: 13px;height: 20px;color:black" 
			@click="returnIndex()"
			></image>
        </view>
        <view class="titleCenter" >
          <b class="titleText">设置</b>
        </view>
        <view class="titleRight"  style="color: #269cd3;flex:1" > </view>
      </view>
    </view>
		<view class="list-cell b-b m-t" @click="navTo('/pages/user/info')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">个人信息</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b" @click="navTo('/pages/address/address')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">收货地址</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view v-if="!isGzyhUser" class="list-cell b-b" @click="navTo('/pages/invoice/invoice')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">发票信息</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b" @click="navTo('/pages/set/modifyPwd')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">修改密码</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b" @click="navTo('/pages/set/feedBack')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">意见反馈</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b" @click="navTo('/pages/set/versionRecord')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">版本记录</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view v-show="false" class="list-cell" @click="disconnectWeixin" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">解绑微信</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<!-- 		<view class="list-cell" @click="navTo('实名认证')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">实名认证</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		
		<view class="list-cell m-t">
			<text class="cell-tit">消息推送</text>
			<switch checked color="#fa436a" @change="switchChange" />
		</view>
		<view class="list-cell m-t b-b" @click="navTo('清除缓存')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">清除缓存</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b" @click="navTo('关于Dcloud')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">关于Dcloud</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell">
			<text class="cell-tit">检查更新</text>
			<text class="cell-tip">当前版本 1.0.3</text>
			<text class="cell-more yticon icon-you"></text>
		</view> -->
		<view class="list-cell log-out-btn" @click="switchUser">
			<text class="cell-tit2">切换账号</text>
		</view>
		<view class="list-cell log-out-btn" @click="toLogout">
			<text class="cell-tit themeTextColor">退出登录</text>
		</view>
		<u-picker
		  mode="selector"
		  v-model="pickerShow"
		  @confirm="pickerConfirm"
		  @columnchange="columnChange"
		  :range="depRange"
		  range-key="fullDeptName"
		>
		</u-picker>
	</view>
</template>

<script>
	import {  goback } from "@/common/utils/navigateBack.js";
	import {
		mapMutations,
		mapState,
	} from 'vuex';
	import {getMobileBindInfo, unBindWx,switch111,qryConfByItemCode} from '../../api/user/user.js'
	export default {
		data() {
			return {
			// 部门选择弹窗
			pickerShow: false,
			range: [],
			jsencryptPwd:'Aa111111',
			isGzyhUser:false
			};
		},
		onShow(){
			this.jsencryptPwd = uni.getStorageSync('jsencryptPwd')
			// 获取微信绑定信息
			const userInfo = uni.getStorageSync('userInfo');
			if (userInfo) {
				getMobileBindInfo({mobile: userInfo.mobile}).then(res => {
					console.log(res);
					if (res.code == 0) {
						this.wxBind = true;
					}
				})
			}
		},
		onLoad() {
			this.getIsGzyh()
		},
		computed:{
			...mapState(['depRange']),
		},
		methods: {
			getIsGzyh(){
				const deptInfo = uni.getStorageSync('deptinfo')[0]
				qryConfByItemCode({code: "isGzyhUser",
					tenant_id: deptInfo.tenantId,
					dept_code: deptInfo.deptCode}).then(res=>{
						if(res.code===0){
							this.isGzyhUser = res.data.val == '1'
						}
				})
			},
			returnIndex() {
				goback()
			},
			...mapMutations(['logout']),
			//切换账号
			switchUser(){
				this.pickerShow=true
				console.log('depRange',this.depRange) 
			},
			columnChange(e) {},
			pickerConfirm2(e){
				const params = {
					userCode:this.depRange[e[0]].userCode
				}
				// var formData=new FormData();
				// formData.append('userCode',this.depRange[e[0]].userCode)
				switch111(params).then(res=>{
					if(res.code == 0){
						console.log('ressssss',res);
						uni.setStorageSync('token', res.data.authToken);
					}
				})
			},
			pickerConfirm(e) {
			  if(this.wxLogin) {
			    this.wxLogin = false;
			    const param = {
			      key: this.deptInfoKey,
			      userCode: this.depRange[e[0]].userCode
			    }
			    this.$store.dispatch('wxSelectDept', param).then(res => {
			      if (res.code === 0) {
			        this.$util.msg("登录成功");
			        uni.navigateTo({
						 url: '/pages/user/user'
					});
			      } else {
			        this.$util.msg(res.message);
			      }
			    });
			    return;
			  }
			  const deptLoginData = {
			    deptId: this.depRange[e[0]].deptId,
			    key: this.key,
			    passwd: this.jsencryptPwd,
			    tenantId: this.depRange[e[0]].tenantId,
			    userCode: this.depRange[e[0]].userCode,
			  };
			  this.$store.dispatch("selectedDeptLogin", deptLoginData).then((res) => {
			    this.logining = false;
			    if (res.code === 0) {
			      this.$util.msg("登录成功");
			    //   this.bindOrToIndex();
				setTimeout(()=>{
					// uni.navigateTo({
					// 	 url: '/pages/user/user'
					// });
					uni.navigateBack()
				},300)
				
			    } else {
			      deptLoginData;
			      this.$util.msg(res.message);
			    }
			  });
			},
			// 解绑微信
			disconnectWeixin(){
				const that = this;
				uni.showModal({
					title: '提示',
					content: '解绑后微信不再接收待办消息，是否确认解绑？',
					confirmColor: '#000000',
					success: suc => {
						if (suc.confirm) {
							unBindWx().then(res => {
								if(res.code == 0) {
									that.wxBind = false;
									that.$api.msg(`解绑成功`)
								}
							})
						}
					}
				})
			},
			navTo(url) {
				uni.navigateTo({
					url
				})
			},
			//不加入路由堆栈
			navToBack(url){
				uni.redirectTo({
					url
				})
			},
			//退出登录
			toLogout() {
				uni.showModal({
					content: '确定要退出登录么',
					success: (e) => {
						if (e.confirm) {
							this.logout();
							uni.setStorageSync('loginInfo', '')
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/public/login'
								});
							}, 200)
						}
					}
				});
			},
			//switch
			switchChange(e) {
				let statusTip = e.detail.value ? '打开' : '关闭';
				this.$api.msg(`${statusTip}消息推送`);
			},

		}
	}
</script>

<style lang='scss'>
	page {
		background: $page-color-base;
	}

	.list-cell {
		display: flex;
		align-items: baseline;
		padding: 20upx $page-row-spacing;
		line-height: 60upx;
		position: relative;
		background: #fff;
		justify-content: center;

		&.log-out-btn {
			margin-top: 30upx;
			.cell-tit {
				text-align: center;
				margin-right: 0;
			}
			.cell-tit2 {
				color: black;
				text-align: center;
				margin-right: 0;
			}
		}

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		&.m-t {
			margin-top: 16upx;
		}

		.cell-more {
			align-self: baseline;
			font-size: $font-lg;
			color: $font-color-light;
			margin-left: 10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: $font-base;
			color: $font-color-light;
		}

		switch {
			transform: translateX(16upx) scale(.84);
		}
	}
</style>
